import { defineStore } from 'pinia'
import {
  reqCategory1,
  reqCategory2,
  reqCategory3,
  reqAttrInfoList,
  reqAddOrEditAttr,
} from '@/api/product/attr'
import type { CategoryResponseData, AttrObj } from '@/api/product/attr/type'
import type { CategoryState } from './types/type'

export const useCategoryStore = defineStore('category', {
  state: (): CategoryState => {
    return {
      c1Arr: [],
      c1Id: '',
      c2Arr: [],
      c2Id: '',
      c3Arr: [],
      c3Id: '',
    }
  },
  actions: {
    //获取一级商品分类
    async getCategory1() {
      let result: CategoryResponseData = await reqCategory1()
      if (result.code === 200) {
        this.c1Arr = result.data
      } else {
      }
    },
    async getCategory2() {
      let result: CategoryResponseData = await reqCategory2(this.c1Id)
      if (result.code === 200) {
        this.c2Arr = result.data
      } else {
      }
    },
    async getCategory3() {
      let result: CategoryResponseData = await reqCategory3(this.c2Id)
      if (result.code === 200) {
        this.c3Arr = result.data
      } else {
      }
    },
    async getAttrInfoList() {
      return await reqAttrInfoList(this.c1Id, this.c2Id, this.c3Id)
    },
  },
})
